package yy.robot.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import yy.robot.domain.Robot;
import yy.robot.repository.RobotRepository;

/**
 * Created by BaiJiFeiLong@gmail.com at 2018/5/7 11:19
 */
@Service
public class RobotService {

    @Autowired
    private RobotRepository robotRepository;

    public Page<Robot> findAll(Pageable pageable) {
        return robotRepository.findAll(pageable);
    }

    public Robot findById(long id) {
        return robotRepository.findById(id).get();
    }

    public Robot create(Robot robot) {
        robotRepository.save(robot);
        return robot;
    }

    public Robot update(Robot robot) {
        robotRepository.save(robot);
        return robot;
    }

    public void destroy(long id) {
        robotRepository.deleteById(id);
    }
}
